package com.epam.kozich.dao;

import java.util.List;

import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


import com.epam.kozich.model.Book;

public class BookDAOImpl extends HibernateDaoSupport implements BookDAO {

	public void addBook(Book book) {
		getHibernateTemplate().save(book);
	}

	public void updateBook(Book book) {
		getHibernateTemplate().update(book);

	}

	public void deleteBook(Book book) {
		getHibernateTemplate().delete(book);

	}

	@SuppressWarnings("unchecked")
	public List<Book> getAllBooks() {
		return getHibernateTemplate().find("from Book");
		// List books = getSession().createCriteria(Book.class)
		//.add(Expression.like("name", "H%")).list();
		//return books;
	}

	@SuppressWarnings("unchecked")
	public List<Book> getEmptyBooks() {
		return getHibernateTemplate().find("from Book where empty=true");
	}

}
